package com.future.message.Service.Impl;

import com.future.message.Mapper.UserMapper;
import com.future.message.pojo.SecurityUser;
import com.future.message.pojo.User;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @projectName:message
 * @see:com.future.message.Service.Impl
 * @author:Xuyujie
 * @createTime:2021/12/4 19:22
 * @version:1.0
 */
@Service
public class UserDetailsImpl implements UserDetailsService {

    @Resource
    private UserMapper userMapper;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.selectByUserName(username);
        if (user == null){
            throw new UsernameNotFoundException("账号不存在！");
        }
        List<String> list = new ArrayList<>();
        list.add(user.getGrade()+"");
        SecurityUser securityUser = new SecurityUser(user, list);
        return  securityUser;
    }
}
